//
//  YBMinePersonalInfoVC.swift
//  Moonlight
//
//  Created by Penlon Kim on 2023/6/30.
//  Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//

import UIKit
import SnapKit

class YBMinePersonalInfoVC: BaseVC {
    
    enum RowType: Int {
        case userName = 0
        case sex
        case age
        case company
        case department
        case job
        
        var des: String {
            switch self {
            case .userName: return "用户名"
            case .sex: return "性别"
            case .age: return "年龄"
            case .company: return "公司"
            case .department: return "部门"
            case .job: return "职业"
            }
        }
    }
    
    private var sections: [[RowType]] = [
        [.userName, .sex, .age],
        [.company, .department, .job]
    ]
    
    // MARK: Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigation.item.title = "个人资料"
        view.backgroundColor = .lightGray242Dark17
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
    }
    
    // MARK: - lazy
    private lazy var tableView: UITableView = {
        let tv = UITableView(frame: .zero, style: .grouped)
        tv.backgroundColor = .clear
        tv.estimatedRowHeight = 44
        tv.separatorStyle = .none
        tv.rowHeight = UITableView.automaticDimension
        tv.delegate = self
        tv.dataSource = self
        tv.showsVerticalScrollIndicator = false
        tv.register(cellWithClass: YBMinePersonalInfoCell.self)
        return tv
    }()
    
}

// MARK: - UITableView代理
extension YBMinePersonalInfoVC: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return sections.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return sections[section].count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let sec = sections[indexPath.section]
        let row = sec[indexPath.row]
        let cell = tableView.dequeueReusableCell(withClass: YBMinePersonalInfoCell.self, for: indexPath)
        cell.kTitleLabel.text = row.des
        switch row {
        case .userName, .sex, .age:
            cell.rightLabel.textColor = kRGBColor(46, 143, 255)
            if row == .userName {
                cell.rightLabel.text = "Mouse"
            } else if row == .sex {
                cell.rightLabel.text = "女"
            } else {
                cell.rightLabel.text = "24"
            }
        case .company, .department, .job:
            cell.rightLabel.textColor = ColorDef.gray153
            cell.rightLabel.text = "暂无"
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let sec = sections[indexPath.section]
        let row = sec[indexPath.row]
        switch row {
        case .userName:
            let vc = YBMineEditInfoVC()
            self.navigationController?.pushViewController(vc)
        case .sex:
            break
        case .age:
            break
        case .company:
            break
        case .department:
            break
        case .job:
            break
        }
    }
    
}
